#
#   MegaKid.py
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 of the License.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   Copyright
#   Author: Salvatore S. Gionfriddo
#   Contributors:
#   Created: 2007.08.07
#   Last Modified: 2007.11.03
#

import pygame

from Boss import Boss
from Animation import Animation

class MegaKid(Boss):
    ###############
    # FRAME TICKS #
    ###############
    ATTACK1_ANIMATION_FRAME_TICKS = 5

    ###################
    # ANIMATION TABLE #
    ###################
    ANIMATION_TABLE = [
        (Boss.IDLE, 'Fink_Run',  Boss.IDLE_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_UP, 'Fink_Run',  Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_DOWN, 'Fink_Run',  Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_SIDE, 'Fink_Run', Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.ATTACK1, 'Fink_Bite', ATTACK1_ANIMATION_FRAME_TICKS, Boss.ATTACK1_KEY_FRAME),
        ]
    
    #############
    # MOVEMENTS #
    #############
    SPEED = 6
#    Y_MOVEMENT = 6
    
#    MOVEMENTS = [(6,0),    #WALK_SIDE
#                 (0,0),    #ATTACK1
#                 ]
    
#########
# STATS #    
#########
    MAX_HEALTH = 12000
    ATTACK1_DAMAGE = 5
    
########
# MISC #
########
    CHANCE_TO_THROW = 50 # twenty in one-thousand
    CAN_THROW = False
    
    GROUPABLE = False
    GROUPER = True
    
    def __init__(self):
        Boss.__init__(self, "Mega")
        self.head = pygame.sprite.Group()
        self.body = pygame.sprite.Group()
        self.larm = pygame.sprite.Group()
        self.rarm = pygame.sprite.Group()
        self.rleg = pygame.sprite.Group()
        self.lleg = pygame.sprite.Group()
        self.groups = [(self.head, 4), (self.body, 2), (self.larm, 4), (self.rarm, 4), (self.rleg, 5), (self.lleg, 5)]
        self.cur_pos = 0
        self.num_pos = 4
        self.count_per_pos = 10
        self.count = 0
        
    def addKid(self, kid):
        distance = 0
        for (group, m) in self.groups:
            if (m - len(group)) > distance:
                body_part = group
                distance = m - len(group)
        if distance:
            kid.grouped = True
            kid.GROUPABLE = False
            body_part.add(kid)
    
    def update(self, collision = None, evilGregRect = 0):
        self.count += 1
        if self.count >= self.count_per_pos:
            self.count = 0
            self.cur_pos += 1
            if self.cur_pos >= self.num_pos:
                self.cur_pos = 0
        Boss.update(self, collision, evilGregRect)
        cX = self.rect.left
        cY = self.rect.top
        # Move attached kids
        #    legs
        #       rleg
        i = 1
        for kid in self.rleg:
            (x,y) = (i*10 + cX - (self.cur_pos * 5 * i), i*15 + cY + 25)
            kid.setPosition((x,y))
            i += 1
        #       lleg
        i = 1
        for kid in self.lleg:
            (x,y) = (i*-10 + cX + (self.cur_pos * 5 * i), i*15 + cY + 25)
            kid.setPosition((x,y))
            i += 1
        #    torso
        i = 0
        p = [-12, 12]
        for kid in self.body:
            (x,y) = (cX + p[i], cY - 9)
            kid.setPosition((x,y))
            i += 1
        #    arms
        #       rarm
        i = 1
        for kid in self.rarm:
            (x,y) = (i*20 + cX + 20, cY + (self.cur_pos * 3 * i))
            kid.setPosition((x,y))
            i += 1
        #       larm
        i = 1
        for kid in self.larm:
            (x,y) = (i*-20 + cX - 20, cY + (self.cur_pos * 3 * i))
            kid.setPosition((x,y))
            i += 1
        #    head
        i = 0
        px = [-12, 12, -12, 12]
        py = [0,0,-15,-15]
        for kid in self.head:
            (x,y) = (cX + px[i], cY - 25 + py[i])
            kid.setPosition((x,y))
            i += 1
        
    def kill(self):
        for (group,c) in self.groups:
            group.empty()
        Boss.kill(self)
        
class RingKid(Boss):
    ###############
    # FRAME TICKS #
    ###############
    ATTACK1_ANIMATION_FRAME_TICKS = 5

    ###################
    # ANIMATION TABLE #
    ###################
    ANIMATION_TABLE = [
        (Boss.IDLE, 'Fink_Run',  Boss.IDLE_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_UP, 'Fink_Run',  Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_DOWN, 'Fink_Run',  Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.WALK_SIDE, 'Fink_Run', Boss.WALK_ANIMATION_FRAME_TICKS,  Animation.NO_KEY_FRAME),
        (Boss.ATTACK1, 'Fink_Bite', ATTACK1_ANIMATION_FRAME_TICKS, Boss.ATTACK1_KEY_FRAME),
        ]
    
    #############
    # MOVEMENTS #
    #############
    Y_MOVEMENT = 6
    
    MOVEMENTS = [(6,0),    #WALK_SIDE
                 (0,0),    #ATTACK1
                 ]
    
#########
# STATS #    
#########
    MAX_HEALTH = 12000
    ATTACK1_DAMAGE = 5
    
########
# MISC #
########
    CHANCE_TO_THROW = 50 # twenty in one-thousand
    CAN_THROW = True
    
    GROUPABLE = False
    GROUPER = True
    
    def __init__(self):
        Boss.__init__(self, "Ring")
        self.ring = pygame.sprite.Group()
        self.groups = [(self.ring, 16)]
        self.cur_pos = 0
        self.num_pos = 4
        self.count_per_pos = 10
        self.count = 0
        
    def addKid(self, kid):
        distance = 0
        for (group, m) in self.groups:
            if (m - len(group)) > distance:
                body_part = group
                distance = m - len(group)
        if distance:
            kid.grouped = True
            kid.GROUPABLE = False
            body_part.add(kid)
    
    def update(self, collision = None, evilGregRect = 0):
        self.count += 1
        if self.count >= self.count_per_pos:
            self.count = 0
            self.cur_pos += 1
            if self.cur_pos >= self.num_pos:
                self.cur_pos = 0
        Boss.update(self, collision, evilGregRect)
        cX = self.rect.left
        cY = self.rect.top
        # Move attached kids
        #    ring
        i = 0
        px = [  0, -17, -42, -47, -60, -47, -42, -17,  0, 17, 42, 47, 60,  47,  42,  17]
        py = [-60, -47, -42, -17,   0,  17,  42,  47, 60, 47, 42, 17,  0, -17, -42, -47]
        for kid in self.ring:
            (x,y) = (cX + px[i], cY + py[i])
            kid.setPosition((x,y))
            i += 1
        
    def kill(self):
        self.ring.empty()
        Boss.kill(self)
